[#assign ispurchaser = Session.currentRole.roleType == 1]
[#-- 是否显示物流发货方式 --]
[#assign showExpress = !ispurchaser && (showShipId == 0 || ship.shipState == 0)]
[#-- 是否是申请发货 --]
[#assign isReq = ispurchaser && !ship??]
[#-- 是否是主动发货 --]
[#assign isShipSelf = !ispurchaser && showShipId?? && showShipId == 0]
[#-- 是否需要选择发货产品：申请发货及主动发货需要 --]
[#assign needChoosePro = isReq || isShipSelf]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1">
    <title>
    [#if ispurchaser]
        [#if !ship??]申请发货[#else]确认收货[/#if]
    [#else]
        立即发货
    [/#if]
    </title>
    <link href="/res/css/common/baseAzt.css" rel="stylesheet" type="text/css" />
    <link href="/res/css/common/backheadfoot.css" rel="stylesheet" type="text/css" />
    <link href="/res/css/common/backcommon.css" rel="stylesheet" type="text/css" />
    <link href="/res/css/respective/order/back-order.css" rel="stylesheet">
    <style type="text/css">
        .shortTab a {
            text-decoration: none !important;
        }
        .warp.warp-supplier .back-main a.abtn{
        	background-color: rgb(254, 169, 16);
        }
		.warp.warp-supplier .back-main a.abtn:hover{
			color: white;
			background-color: rgb(255, 192, 1);
		}
        /** 滚动条 **/
        ::-webkit-scrollbar{width: 10px; height: 10px;}
        ::-webkit-scrollbar-button:vertical{display: none;}
        ::-webkit-scrollbar-track, ::-webkit-scrollbar-corner{background-color: #e2e2e2;}
        ::-webkit-scrollbar-thumb{border-radius: 0; background-color: rgba(0,0,0,.3);}
        ::-webkit-scrollbar-thumb:vertical:hover{background-color: rgba(0,0,0,.35);}
        ::-webkit-scrollbar-thumb:vertical:active{background-color: rgba(0,0,0,.38);}
    </style>
</head>
<body>
<div class="warp [#if !ispurchaser]warp-supplier[/#if]">
[#include "/front/common/front_headAzt.html"]
    <div class="backcontent">
    [#--[#include "/front/common/front_leftAzt.html"]--]
        <div class="back-main back-main-view">
            <div class="inner">
                <div class="alltitle">
                    [#if ispurchaser]
                        [#if !ship??]申请发货[#else]确认收货[/#if]
                        [#else]
                         立即发货
                    [/#if]
                </div>
                [#-- 显示批次tab --]
                [#if (!ispurchaser && order.ifBatchShip?? && order.ifBatchShip == 1) || (ispurchaser && showShipId?? && order.ifBatchShip?? && order.ifBatchShip == 1)]
                    <div class="backTab shortTab">
                        <ul>
                            [#list shipList as ship]
                                <li [#if showShipId?? && showShipId == ship.id]class="on"[/#if]>
                                    <a href="/order/ship/${order.id!}?shipId=${ship.id!}">第${CommonUtil.num2CN(ship_index + 1)}批</a>
                                </li>
                            [/#list]
                            [#if !ispurchaser && !isShipEnd]
                                <li [#if showShipId?? && showShipId == 0]class="on"[/#if]>
                                    <a href="/order/ship/${order.id!}?shipId=0">第${CommonUtil.num2CN(shipList?size + 1)}批</a>
                                </li>
                            [/#if]
                        </ul>
                    </div>
                    <div class="clear"></div>
                [/#if]
                <div class="orderpayInfo">
                    <h4>项目信息</h4>
                    <div class="cont">
                        <table>
                            <tbody>
                            <tr style="display: block; margin-bottom: 10px;">
                                <td>项目名称：${order.projectName!}</td>
                            </tr>
                            <tr>
                                <td>询价名称：<a href="/xmh/${order.enquiryId!}" target="_blank" title="${order.enquiryName!}">${CommonUtil.getSimpleStr(order.enquiryName!, 20)}</a></td>
                                <td>报价截止时间：${order.deadline?date!} </td>
                            </tr>
                            </tbody>
                        </table>
                    </div>
                </div>
                <div class="dataTable orderTable">
                    <h3>请货清单</h3>
                    <div class="alltd">下单时间：${order.ordertime?datetime!}　　订单号：${order.orderNumber!} &nbsp; &nbsp; &nbsp;
                        <div class="cname" title="${order.companyName!}">卖家：${CommonUtil.getSimpleStr(order.companyName!"", 20)}</div>
                    </div>
                    <table id="detailTable">
                        [#if needChoosePro]
                            <thead>
                            <tr class="tdtitle">
                                <td width="28%">
                                    <p class="name font14" style="font-weight: bold;">
                                        <input type="checkbox" class="pos" style="position: static;" onclick="check(this)" data-check="all"/> 商品名称
                                    </p>
                                </td>
                                <td width="10%">品牌</td>
                                <td width="10%">型号</td>
                                <td width="12%">单价</td>
                                <td width="12%">剩余数量</td>
                                <td width="6%">单位</td>
                                <td width="10%">已申请数量</td>
                                <td width="12%">小计</td>
                            </tr>
                            </thead>
                            [#list detailList as detail]
                            [#-- 显示可以申请发货、主动发货的产品 --]
                                [#if detail.canReqShipQuantity?? && detail.canReqShipQuantity > 0]
                                    <tr data-detailId="${detail.id}" data-price="${detail.price}">
                                        <td>
                                            <p class="name">
                                                <input type="checkbox" class="pos" style="position: static;" onclick="check(this)" data-check="detail"/> ${CommonUtil.getSimpleStr(detail.productName, 20)}
                                            </p>
                                        </td>
                                        <td>${detail.brand}</td>
                                        <td>${detail.model}</td>
                                        <td>￥${detail.price!?string('0.00')}</td>
                                        <td>
                                            <span class="numform">
                                                <a href="javascript:void(0)" class="dec" onclick="btnSub(this)"></a>
                                                <input type="text" value="${detail.canReqShipQuantity}" data-max="${detail.canReqShipQuantity}"
                                                       data-val="${detail.canReqShipQuantity}" onkeyup="enterNum(this)" onblur="blurNum(this)" style="padding-left: 0;"/>
                                                <a href="javascript:void(0)" class="add" onclick="btnAdd(this)"></a>
                                            </span>
                                        </td>
                                        <td>${detail.unit!}</td>
                                        <td>${detail.quantity - detail.canReqShipQuantity!0}</td>
                                        <td>
                                            <b class="orange">￥${(detail.canReqShipQuantity * detail.price)?string('0.00')}</b>
                                        </td>
                                    </tr>
                                [/#if]
                            [/#list]
                            [#else]
                            <thead>
                                <tr class="tdtitle">
                                    <td width="35%">
                                        <p class="name font14" style="font-weight: bold;">
                                            <input type="checkbox" class="pos" onclick="check(this)" data-check="all"/> 商品名称
                                        </p>
                                    </td>
                                    <td width="12%">品牌</td>
                                    <td width="12%">型号</td>
                                    <td width="12%">单价</td>
                                    <td width="12%">数量</td>
                                    <td width="5%">单位</td>
                                    <td width="12%">小计</td>
                                </tr>
                            </thead>
                            [#list detailList as detail]
                            [#-- 显示本批发货的产品 --]
                                <tr class="bg" data-detailId="${detail.id}">
                                    <td>
                                        <p class="name">${CommonUtil.getSimpleStr(detail.productName, 20)}</p>
                                    </td>
                                    <td>${detail.brand!}</td>
                                    <td>${detail.model!}</td>
                                    <td>￥${detail.price!}</td>
                                    <td>${detail.quantity!}</td>
                                    <td>${detail.unit!}</td>
                                    <td>
                                        <b >￥${(detail.quantity * detail.price)?string('0.00')}</b>
                                    </td>
                                </tr>
                            [/#list]
                        [/#if]

                    </table>
                </div>

                <div class="orderviewDetail orderviewDetail2">
                    [#if isReq]
                        <div class="fr" id="reqBtn">
                            <a href="javascript:void(0)" onclick="ship()" class="abtn">提交发货申请</a>
                        </div>
                        <div class="msgcont" style="visibility: hidden;">已选商品：<b class="orange"></b> 件 合计<b class="orange"></b></div>
                    [/#if]

                    [#if ispurchaser && ship?? && ship.shipState == 1]
                        <div class="takegood">
                            <p class="red">请收到货后再确认，多批次发货，请分别完成确认收货。</p>
                            <ul>
                                <li>
                                    <label>账号：</label>
                                    <div class="tfile">
                                        ${Session.currentUser.hiddenUserName!}
                                        <a href="javascript:void(0)" class="ma" onclick="sendCode()" id="codebtn">获取验证码</a>
                                        <a href="javascript:void(0)" id="timebtn" style="display: none; cursor: default; height: 28px; line-height: 28px; width: 94px; margin-left: 20px; text-align: center; border-radius: 3px; color: #c9cfd6; border: 1px solid #cfcfcf; text-decoration: none;">30秒</a>
                                    </div>
                                </li>
                                <li>
                                    <label style="line-height:40px;">验证码：</label>
                                    <div class="tfile">
                                        <input type="text" placeholder="请输入验证码" id="code"/>
                                    </div>
                                </li>
                                <li>
                                    <label>&nbsp;</label>
                                    <div class="tfile">
                                        <a href="javascript:void(0)" onclick="ship()" class="abtn">确认收货</a>
                                    </div>
                                </li>
                            </ul>
                        </div>
                    [/#if]

                </div>

                [#if showExpress]
                <div class="orderpayInfo logisticsCh">
                    <h4>选择物流</h4>
                    <div class="cont">
                        <div class="logtabtitle">
                            <a href="javascript:void(0)" class="on" data-shipType="1">物流配送<span></span></a>
                            <a href="javascript:void(0)" data-shipType="2">车辆配载<span></span></a>
                            <a href="javascript:void(0)" data-shipType="3">自提<span></span></a>
                        </div>
                        <div class="logtabcont">
                            <div class="ilogtabcont">
                                <ul>
                                    <li>
                                        <label>快递公司：</label>
                                        <div class="inputfile">
                                            <select id="deliveryCompanyId" data-display="快递公司" data-rule="required(.logtabtitle a[data-shipType=1].on)">
                                                <option value="">请选择</option>
                                                [#list deliveryList as delivery]
                                                    <option value="${delivery.id!}">${delivery.companyName!}</option>
                                                [/#list]
                                            </select>
                                        </div>
                                    </li>
                                    <li>
                                        <label>运单号：</label>
                                        <div class="inputfile">
                                            <input type="text" placeholder="请输入运单号" id="expressNumber" data-display="运单号" data-rule="required(.logtabtitle a[data-shipType=1].on)"/>
                                        </div>
                                    </li>
                                    <li>
                                        <label>&nbsp; </label>
                                        <div class="inputfile">
                                            <a href="javascript:void(0)" onclick="ship()" class="abtn">确认发货</a>
                                        </div>
                                    </li>
                                </ul>
                            </div>
                            <div class="ilogtabcont" style="display:none">
                                <ul>
                                    <li>
                                        <label>车牌号：</label>
                                        <div class="inputfile">
                                            <input type="text" placeholder="请输入车牌号" id="plateNumber" data-display="车牌号" data-rule="required(.logtabtitle a[data-shipType=2].on)"/>
                                        </div>
                                    </li>
                                    <li>
                                        <label>配送人：</label>
                                        <div class="inputfile">
                                            <input type="text" placeholder="请输入配送人" id="contacts2" data-display="配送人" data-rule="required(.logtabtitle a[data-shipType=2].on)"/>
                                        </div>
                                    </li>
                                    <li>
                                        <label>手机号：</label>
                                        <div class="inputfile">
                                            <input type="text" placeholder="请输入手机号" id="contactTel2" data-display="手机号" data-rule="required(.logtabtitle a[data-shipType=2].on); sj" data-rule-sj="$('.logtabtitle a[data-shipType=2].on').length == 1 ? [/^1[3-9]\d{9}$/, '请填写有效的手机号'] : true"/>
                                        </div>
                                    </li>
                                    <li>
                                        <label>出发日期：</label>
                                        <div class="inputfile">
                                            <input type="text" placeholder="请选择出发日期" id="departTime" onclick="laydate({format: 'YYYY-MM-DD', max: laydate.now(), choose: function() {$('.back-main').validator('hideMsg', '#departTime');}})"/>
                                        </div>
                                    </li>
                                    <li>
                                        <label>&nbsp; </label>
                                        <div class="inputfile">
                                            <a href="javascript:void(0)" onclick="ship()" class="abtn">确认发货</a>
                                        </div>
                                    </li>
                                </ul>
                            </div>
                            <div class="ilogtabcont" style="display:none">
                                <ul>
                                    <li>
                                        <label>提货地点：</label>
                                        <div class="inputfile">
                                            <input type="text" placeholder="请输入提货地点" id="pickAddress" data-display="提货地点" data-rule="required(.logtabtitle a[data-shipType=3].on)"/>
                                        </div>
                                    </li>
                                    <li>
                                        <label>联系人：</label>
                                        <div class="inputfile">
                                            <input type="text" placeholder="请输入联系人" id="contacts3" data-display="联系人" data-rule="required(.logtabtitle a[data-shipType=3].on)"/>
                                        </div>
                                    </li>
                                    <li>
                                        <label>手机号：</label>
                                        <div class="inputfile">
                                            <input type="text" placeholder="请输入手机号" id="contactTel3" data-display="手机号" data-rule="required(.logtabtitle a[data-shipType=3].on); sj" data-rule-sj="$('.logtabtitle a[data-shipType=3].on').length == 1 ? [/^1[3-9]\d{9}$/, '请填写有效的手机号'] : true"/>
                                        </div>
                                    </li>
                                    <li>
                                        <label>&nbsp; </label>
                                        <div class="inputfile">
                                            <a href="javascript:void(0)" onclick="ship()" class="abtn">确认发货</a>
                                        </div>
                                    </li>
                                </ul>
                            </div>
                        </div>
                    </div>
                </div>
                [/#if]

                [#-- 支付成功的总金额 --]
                [#assign payTotalPrice = 0]

                <div class="orderpayInfo">
                    <h4>支付信息</h4>
                    <div class="cont">
                        [#if payList?? && payList?size > 0]
                            [#list payList as pay]
                                [#assign payTotalPrice = payTotalPrice + pay.totalPrice]
                                [#if pay_index != 0]<div class="line">[/#if]
                                    <table>
                                        <tbody>
                                        <tr>
                                            <td style="width: 40%;"><b>[#if order.ifBatchPay?? && order.ifBatchPay == 0]一次性支付[#else]第${pay_index + 1}批[/#if]：</b>应付金额：¥${pay.totalPrice!}</td>
                                            <td style="width: 20%;">安装币抵扣：¥${pay.dePrice!0.00}</td>
                                            <td style="width: 20%;">实付金额：¥${(pay.totalPrice - pay.dePrice!0)?string('0.00')}</td>
                                            <td style="width: 20%;">支付方式：${PayMode[pay.payMode?string]!}</td>
                                        </tr>
                                        [#if !pay_has_next && payTotalPrice < order.totalPrice]
                                            <tr>
                                                <td colspan="5"><p class="surplus" style="padding-left: 0;">
                                                    <b>剩余金额：</b><span class="orange">¥${order.totalPrice - payTotalPrice}</span></p>
                                                </td>
                                            </tr>
                                        [/#if]
                                        </tbody>
                                    </table>
                                [#if pay_index != 0]</div>[/#if]
                            [/#list]
                            [#else]
                                <table>
                                    <tbody>
                                    <tr>
                                        <td width="50%"><span>暂无支付信息</span></td>
                                    </tr>
                                    </tbody>
                                </table>
                        [/#if]
                    </div>
                </div>

                [#-- 已确认收货的总金额 --]
                [#assign signTotalPrice = 0]
                [#if shipList?? && shipList?size > 0]
                <div class="orderpayInfo">
                    <h4>发货信息</h4>
                    <div class="cont">
                        [#list shipList as ship]
                            [#if ship.shipState == 2][#assign signTotalPrice = signTotalPrice + ship.totalPrice][/#if]
                            [#if ship_index != 0]<div class="line">[/#if]
                                <table>
                                    <tbody>
                                    <tr>
                                        <td style="width: 25%;">
                                            <b>[#if order.ifBatchShip?? && order.ifBatchShip == 0]一次性发货[#else]第${ship_index + 1}批[/#if]：</b>
                                            [#if ship.ifApply == 0]未请货[#else]请货金额：¥${ship.totalPrice?string('0.00')!} &nbsp;&nbsp;&nbsp;[/#if]
                                        </td>
                                        <td style="width: 25%;">
                                        [#if ship.ifApply?? && ship.ifApply == 1]
                                            <em style="font-style: normal;">请货时间：[#if ship.createtime??]${ship.createtime?datetime!}[/#if]</em>
                                        [/#if]
                                        </td>
                                        <td style="width: 25%;">已发货金额：[#if ship.shipState == 0]未发货[#else]¥${ship.totalPrice?string('0.00')!}[/#if]</td>
                                        [#if ship.shipState != 0]<td style="width: 20%;">发货时间：[#if ship.shipTime??]${ship.shipTime?datetime!}[/#if]</td>[/#if]
                                        <td style="text-align: center;"><a href="/order/shipDetail/${order.id!}/${ship.id!}?index=${ship_index + 1}" target="_blank">查看详情</a></td>
                                    </tr>
                                    </tbody>
                                </table>
                            [#if ship_index != 0]</div>[/#if]
                        [/#list]
                    </div>
                </div>
                [/#if]

                <div class="orderpayInfo" id="addressInfo">
                    <input type="hidden" id="receiptName" value="${address.receiptName!}">
                    <input type="hidden" id="receiptTel" value="${address.receiptTel!}">
                    <input type="hidden" id="receiptPhone" value="${address.receiptPhone!}">
                    <input type="hidden" id="receiptProvince" value="${address.receiptProvince!}">
                    <input type="hidden" id="receiptCity" value="${address.receiptCity!}">
                    <input type="hidden" id="receiptArea" value="${address.receiptArea!}">
                    <input type="hidden" id="receiptAddress" value="${address.receiptAddress!}">
                    <h4>收货信息</h4>
                    <div class="cont">
                        <table class="patd10">
                            <tbody>
                            <tr>
                                <td><span class="gray">姓名：</span><span>${address.receiptName!}</span></td>
                                <td><span class="gray">联系电话：</span><span>[#if address.receiptTel??]${address.receiptTel!}[#else]${address.receiptPhone!}[/#if]</span></td>
                            </tr>
                            <tr>
                                <td colspan="2"><span class="gray">收货信息：</span><span>${address.receiptProvinceName!} ${address.receiptCityName!} ${address.receiptAreaName!} ${address.receiptAddress!}</span></td>
                            </tr>
                            [#if showExpress]
                            <tr>
                                <td><a href="javascript:void(0)" onclick="showAddressWin()" style="text-decoration: none;">修改收货地址</a></td>
                            </tr>
                            [/#if]
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>

[#include "/front/common/front_footerAzt.html"]
</div>

<!-- 修改收货地址弹出框 -->
<div class="tanbox tanEditAddress" style="display:none" id="addressWin">
    <div class="tanbg"></div>
    <div class="box">
        <div class="title"><span class="closed"></span>修改收货地址</div>
        <form id="addressForm" data-validator-option="{theme:'yellow_right', timely:3}">
            <div class="cont">
                <ul>
                    <li>
                        <label>收货人：</label>
                        <div class="inputfile">
                            <input type="text" id="ship_receiptName" class="input" data-display="收货人" data-rule="required"/>
                        </div>
                    </li>
                    <li>
                        <label>所在地区：</label>
                        <div class="inputfile">
                            <div class="d1">
                                <select id="ship_province" data-display="所在地区" data-rule="required" data-target="#ship_district">
                                    <option>请选择省/直辖市</option>
                                </select>
                                <select id="ship_city" data-display="所在地区" data-rule="required" data-target="#ship_district">
                                    <option>请选择省/直辖市</option>
                                </select>
                                <select class="last" id="ship_district" data-display="所在地区" data-rule="required">
                                    <option>请选择省/直辖市</option>
                                </select>
                            </div>
                            <div class="d2">
                                <input type="text" class="input" id="ship_receiptAddress" placeholder="详细地址" data-display="详细地址" data-rule="required"/>
                            </div>
                        </div>
                    </li>
                    <li>
                        <label>手机号码：</label>
                        <div class="inputfile">
                            <input type="text" id="ship_receiptTel" class="input telPhone" placeholder="请填写常用手机号码"
                                   data-display="手机号码" data-rule="required(from, .telPhone);mobile" data-msg-required="请至少填写一种联系方式"/>
                        </div>
                    </li>
                    <li>
                        <label>固定电话：</label>
                        <div class="inputfile">
                            <input type="text" class="input telPhone" id="ship_receiptPhone" placeholder="固定电话"
                                   data-display="固定电话" data-rule="required(from, .telPhone)"/>
                        </div>
                    </li>
                    <li>
                        <label>&nbsp;</label>
                        <div class="inputfile btn btn-left">
                            <a href="javascript:void(0)" class="save" onclick="saveAddress()">保存收货地址</a>
                            <a href="javascript:void(0)" onclick="$('#addressWin').hide()">取消</a>
                        </div>
                    </li>
                </ul>
            </div>
        </form>
    </div>
</div>

<div id="reqConfirmWin" style="display: none">
    <div style="padding-left: 55px; background: url(/res/images/oparaStatus/tan.png) no-repeat left center; min-height: 44px;">
        本次请货金额为 ￥<span></span>，大于您已支付金额 ￥${payTotalPrice}，是否确定请货？
    </div>
</div>

<script type="text/javascript" src="/res/js/structure/struture.js"></script>
<script type="text/javascript" src="/res/js/common/common.js"></script>
<script type="text/javascript" src="/res/third/laydate/laydate.js"></script>
<script type="text/javascript" src="/res/third/layer/layer.js"></script>
<script type="text/javascript" src="/res/js/common/tppl.js"></script>
<script type="text/javascript" src="/res/js/common/util.js"></script>
<script type="text/javascript" src="/res/third/nice-validator/jquery.validator.min.js?local=zh-CN"></script>
<script type="text/javascript" src="/res/js/common/jquery.freezeheader.js"></script>
<script type="text/javascript" src="/res/js/common/jquery.address.js"></script>
<script type="text/javascript">
    $(function () {
        //初始化校验
        $('.back-main').validator({
            formClass: 'n-yellow',
            msgClass: 'n-right',
            msgArrow: '<span class="n-arrow"><b>◆</b><i>◆</i></span>',
            timely : 3
        });

        //如果无发货清单可选，则隐藏全选check
        if($('#detailTable tr[data-detailid] input[type=checkbox]').length == 0) {
            $('#detailTable input[data-check=all]').hide();
            $('#reqBtn').hide();
        }

        //固定表头
        if($("#detailTable").height() > 715) {
            $("#detailTable").freezeHeader({height: '751px'});
        }

        //选择物流
        $('.logtabtitle a').click(function(){
            $(this).siblings().removeClass('on').end().addClass('on');
            $('.logisticsCh .ilogtabcont').hide().eq($(this).index()).show();

            $('.logisticsCh .ilogtabcont').eq($(this).index()).each(function() {
                $.each($(this).find('input[type=text]'), function() {
                    $('.back-main').validator('hideMsg', this);
                });
                $.each($(this).find('select'), function() {
                    $('.back-main').validator('hideMsg', this);
                });
            });
            return false;
        });
        $('.tanbox .closed').click(function(){
            $(this).parents('.tanbox').hide();
        });

        //初始化收货地址
        //new newAddress('ship', 'select', 0, 1, 3, 1);
    });

    //数量+
    function btnAdd(obj) {
        var $input = $(obj).prev();
        var value = Number($input.val());
        if(value) {
            var max = $input.attr('data-max');
            var next = add(value, 1);
            var val = next > max ? max : next;
            $input.val(val);
            $input.parents('tr').find('td:last b').html('￥' + Math.round(mul(val, Number($input.parents('tr').attr('data-price'))) * 100) / 100);
        }
        calcCheckedPrice();
    }

    //数量-
    function btnSub(obj) {
        var $input = $(obj).next();
        var min = 1;
        var value = Number($input.val());
        if(value) {
            var next = sub(value, 1);
            var val = next < min ? min : next;
            $input.val(val);
            $input.parents('tr').find('td:last b').html('￥' + Math.round(mul(val, Number($input.parents('tr').attr('data-price'))) * 100) / 100);
        }
        calcCheckedPrice();
    }

    //手动输入数量
    function enterNum(obj) {
        calcCheckedPrice();
        var $input = $(obj);
        var max = Number($input.attr('data-max'));
        var min = 1;
        var value = Number($input.val());
        if(value) {
            if(value >= min && value <= max) {
                var _price = Math.round(mul(value, $input.parents('tr').attr('data-price')) * 100)/100;
                $input.parents('tr').find('td:last b').html('￥' + _price.toFixed(2));
                return;
            }
        }
        //$input.parents('tr').find('td:last b').html('数量错误');
        calcCheckedPrice();
    }

    //数量输入框丢失焦点
    function blurNum(obj) {
        calcCheckedPrice();
        var $input = $(obj);
        var max = Number($input.attr('data-max'));
        var min = 1;
        var value = Number($input.val());
        if(value) {
            if(value >= min && value <= max && /^([1-9]\d*|0)(\.\d{1,4})?$/.test(value)) {
                $input.parents('tr').find('td:last b').html('￥' + (Math.round(mul(value, $input.parents('tr').attr('data-price')) * 100) / 100).toFixed(2));
                return;
            }
        }
        $input.val($input.attr('data-val'));
        $input.parents('tr').find('td:last b').html('￥' + (Math.round(mul($input.val(), $input.parents('tr').attr('data-price')) * 100) / 100).toFixed(2));
        calcCheckedPrice();
    }

    function check(obj) {
        $check = $(obj);
        if($check.attr('data-check') == 'all') {
            //全选
            $('#detailTable input[data-check=detail]').prop('checked', $check.prop('checked'));
        } else {
            var allCheck = $('#detailTable input[data-check=detail]:checked').length == $('#detailTable input[data-check=detail]').length;
            $('#detailTable input[data-check=all]').prop('checked', allCheck);
        }
        calcCheckedPrice();
    }

    function ship() {
        if(!$('.back-main').isValid()) {
            //单独校验出发日期
            if($('.logtabtitle a[data-shipType=2].on').length > 0 && $('#departTime').val() == '') {
                $('.back-main').validator('showMsg', '#departTime', {
                    type: "error",
                    msg: "出发日期不能为空"
                });
            } else {
                $('.back-main').validator('hideMsg', '#departTime');
            }
            return;
        }
        //单独校验出发日期
        if($('.logtabtitle a[data-shipType=2].on').length > 0 && $('#departTime').val() == '') {
            $('.back-main').validator('showMsg', '#departTime', {
                type: "error",
                msg: "出发日期不能为空"
            });
            return;
        } else {
            $('.back-main').validator('hideMsg', '#departTime');
        }

        var data = {};      //提交到后台的数据
        var shipId = '${showShipId!}';
        var orderId = '${order.id}';
        var detailIds = ''; //发货产品
        var quantitys = ''; //发货数量
        var code = $('#code').val();      //确认收货时候的验证码
        var numError = false;
        var reqPrice = 0;   //本次申请发货总金额
        $('#detailTable input[data-check=detail]:checked').each(function() {
            var $input = $(this).parents('tr').find('input[data-max]');
            if(Number($input.val()) && $input.val() >= 1 && $input.val() <= $input.attr('data-max')) {
                detailIds += $(this).parents('tr').attr('data-detailId') + ',';
                quantitys += $(this).parents('tr').find('input[data-max]').val() + ',';

                reqPrice = add(reqPrice, Math.round(mul(Number($input.val()), Number($input.parents('tr').attr('data-price'))) * 100) / 100);
            } else {
                layer.alert("数量输入错误");
                numError = true;
                return false;
            }
        });
        if(numError) {
            return;
        }
        if(detailIds != '') {
            detailIds = detailIds.substring(0, detailIds.length - 1);
        }
        if(quantitys != '') {
            quantitys = quantitys.substring(0, quantitys.length - 1);
        }

        //物流
        var shipType = $('.logtabtitle a[data-shipType].on').attr('data-shipType');
        if(shipType == 1) {
            //物流配送
            data.shipType = shipType;
            data.deliveryCompanyId = $('#deliveryCompanyId').val();
            data.expressNumber = $('#expressNumber').val();
        } else if(shipType == 2) {
            //车辆配载
            data.shipType = shipType;
            data.plateNumber = $('#plateNumber').val();
            data.contacts = $('#contacts2').val();
            data.contactTel = $('#contactTel2').val();
            data.departTime = $('#departTime').val();
        } else if(shipType == 3) {
            //自提
            data.shipType = shipType;
            data.pickAddress = $('#pickAddress').val();
            data.contacts = $('#contacts3').val();
            data.contactTel = $('#contactTel3').val();
        }

        //确认收货，校验验证码
        [#if ispurchaser && ship?? && ship.shipState == 1]
        if($.trim(code) == '') {
            layer.alert('请输入验证码');
            return;
        }
        data.code = code;
        [/#if]
        //申请发货、主动发货，校验发货清单是否选择
        [#if needChoosePro]
            if(detailIds == '' || quantitys == '') {
                layer.alert("请选择要请货的商品");
                return;
            }
            data.detailIds = detailIds;
            data.quantitys = quantitys;
        [/#if]
        [#if showExpress]
            var receiptName = $('#receiptName').val();
            var receiptTel = $('#receiptTel').val();
            var receiptPhone = $('#receiptPhone').val();
            var receiptProvince = $('#receiptProvince').val();
            var receiptCity = $('#receiptCity').val();
            var receiptArea = $('#receiptArea').val();
            var receiptAddress = $('#receiptAddress').val();
            if(receiptName == '' || (receiptTel == '' && receiptPhone == '') || receiptProvince == '' || receiptCity == '' || receiptArea == '' || receiptAddress == '') {
                layer.alert('请输入收货信息');
                return;
            }
            data.receiptName = receiptName;
            data.receiptTel = receiptTel;
            data.receiptPhone = receiptPhone;
            data.receiptProvince = receiptProvince;
            data.receiptCity = receiptCity;
            data.receiptArea = receiptArea;
            data.receiptAddress = receiptAddress;
        [/#if]

        data.shipId = shipId;
        data.orderId = orderId;

        if(!checkSign()) {
            return;
        }

        [#if isReq]
        if(reqPrice > Number('${payTotalPrice}')) {
            $('#reqConfirmWin span').html(reqPrice);
            layer.confirm($('#reqConfirmWin').html(), function() {
                doship(data);
            });
        } else {
            doship(data);
        }
        [#else]
            doship(data);
        [/#if]
    }

    function doship(data) {
        $.ajax({
            url : '/order/ship',
            type : 'post',
            dataType : 'json',
            data : data,
            beforeSend : function () {
                layer.load(2, {shade: 0.1});
            },
            success : function(res) {
                if(res.success) {
                    layer.alert('操作成功', {closeBtn: 0}, function() {
                        location.replace('/order/${order.id!}');
                    });
                } else {
                    layer.alert(res.msg);
                }
            },
            complete : function() {
                layer.closeAll('loading');
            }
        });
    }

    //发送确认收货验证码
    function sendCode() {
        if(!checkSign()) {
            return;
        }
        [#if ship??]
        $.ajax({
            url : '/order/signCode',
            type : 'post',
            dataType : 'json',
            data : {orderId : '${order.id!}', shipId : '${ship.id!}'},
            beforeSend : function() {
                layer.load(2, {shade: 0.1});
            },
            success : function(data) {
                if(data.success) {
                    $('#codebtn').hide();
                    $('#timebtn').text('30秒');
                    $('#timebtn').css('display', 'inline-block');
                    codeTimeLoop();
                } else {
                    layer.alert(data.msg);
                }
            },
            complete : function() {
                layer.closeAll('loading');
            }
        });
        [/#if]
    }

    //验证码倒计时
    var loopId;
    function codeTimeLoop() {
        loopId = setInterval(function() {
            var time = Number($('#timebtn').text().replace('秒', ''));
            if(time == 1) {
                $('#timebtn').hide();
                $('#codebtn').css('display', 'inline-block');
                clearInterval(loopId);
            } else {
                $('#timebtn').text((time - 1) + '秒');
            }
        }, 1000);
    }

    function showAddressWin() {
        $('#ship_receiptName').val($('#receiptName').val());
        $('#ship_receiptTel').val($('#receiptTel').val());
        $('#ship_receiptPhone').val($('#receiptPhone').val());
        $('#ship_province').attr('data-val', $('#receiptProvince').val());
        $('#ship_city').attr('data-val', $('#receiptCity').val());
        $('#ship_district').attr('data-val', $('#receiptArea').val());
        $('#ship_receiptAddress').val($('#receiptAddress').val());

        layer.load(2, {shade: 0.1});
        $.address({
            province : 'ship_province',
            city : 'ship_city',
            district : 'ship_district',
            success : function() {
                $('#addressForm').validator('cleanUp');
                if($("body").find(".warp-supplier").size()>0){
                    $(".tanbox .btn-left a").addClass("supOrg");
                }
                $('#addressWin').show();
                layer.closeAll('loading');
            }
        });
    }

    function saveAddress() {
        if($('#addressForm').isValid()) {
            //更新隐藏域
            $('#receiptName').val($('#ship_receiptName').val());
            $('#receiptTel').val($('#ship_receiptTel').val());
            $('#receiptPhone').val($('#ship_receiptPhone').val());
            $('#receiptProvince').val($('#ship_province').val());
            $('#receiptCity').val($('#ship_city').val());
            $('#receiptArea').val($('#ship_district').val());
            $('#receiptAddress').val($('#ship_receiptAddress').val());
            //更新显示域
            $('#addressInfo table tr:eq(0) td:eq(0) span:eq(1)').text($('#ship_receiptName').val());
            $('#addressInfo table tr:eq(0) td:eq(1) span:eq(1)').text($('#ship_receiptTel').val() != '' ? $('#ship_receiptTel').val() : $('#ship_receiptPhone').val());
            $('#addressInfo table tr:eq(1) td:eq(0) span:eq(1)').text($('#ship_province option:selected').text() + " " + $('#ship_city option:selected').text() + " " + $('#ship_district option:selected').text() + " " + $('#ship_receiptAddress').val());
            $('#addressWin').hide();
        }
    }

    function calcCheckedPrice() {
        var quantity = 0;
        var price = 0;
        $('#detailTable input[data-check=detail]:checked').each(function() {
            var $input = $(this).parents('tr').find('input[data-max]');
            if(Number($input.val()) && Number($input.val()) >= 1 && Number($input.val()) <= Number($input.attr('data-max'))) {
                quantity = add(quantity, Number($input.val()));
                price = add(price, Math.round(mul(Number($input.val()), Number($input.parents('tr').attr('data-price'))) * 100) / 100);
            }
        });
        if(quantity > 0) {
            $('.msgcont').css('visibility', 'visible');
            $('.msgcont b.orange:eq(0)').html(quantity);
            $('.msgcont b.orange:eq(1)').html('￥' + price);
        } else {
            $('.msgcont').css('visibility', 'hidden');
        }
    }

    /**
     * 判断是否可以确认收货，如果已付完全部款项，则均可确认收货，否则付款金额需大于之前确认收货的货物金额 + 本次确认收货的金额
     * */
    function checkSign() {
        var flag = true;
        [#if ispurchaser && ship?? && ship.shipState == 1]
            var payTotalPrice = Number('${payTotalPrice}');     //付款总金额
            var orderPrice = Number('${order.totalPrice}');       //订单总金额
            var originalPrice = Number('${order.originalPrice}');
            var unPayPrice = sub(orderPrice, payTotalPrice);    //未支付金额
            var signTotalPrice = Number('${signTotalPrice}');   //之前确认收货的总额
            var thisSignPrice = Number('${ship.totalPrice}');   //本次确认收货的总额
            if(unPayPrice > 0 && payTotalPrice < add(signTotalPrice, thisSignPrice)) {
                var price = sub(add(signTotalPrice, thisSignPrice), payTotalPrice);
                if(orderPrice != originalPrice && price > unPayPrice) {
                    price = unPayPrice;
                }
                layer.alert("无法确认收货，您已支付¥" + payTotalPrice + "，请到财务中心补足货款¥" + price);
                flag = false;
            }
        [/#if]
        return flag;
    }
</script>
</body>
</html>